{cx:toolbar id="toolbar"}
{/cx:toolbar}

<!-- 表格 -->
<table id="table" data-toggle="gridview" class="table" data-url="/{$Request.module}/{$Request.controller}" data-toolbar="#toolbar" data-show-columns="true" data-page-size="5" data-page-list="[5, 25, 50, All]" data-unique-id="id" data-pagination="true" data-side-pagination="client">
    <thead>
        <tr>
            <th data-width="40"  data-align="center"  data-checkbox="true"></th>
            <th data-width="50" data-field="sort" data-formatter="format_sort">排序</th>
            <th data-field="title">菜单名称</th>
            <th data-field="level">级别</th>
            <th data-field="status" data-formatter="format_status">状态</th>
            <th data-field="url">链接地址</th>
        </tr>
    </thead>
</table>


<div class="gridview2"></div>

<script type="text/javascript">

	var toolbarUrl = '/admin/menu/toolbar?menu=', $menuTable, $btn_gridview;
	$(function() {
		$menuTable = $('#table')
				.on('clickRow',function(e, row, $element) {
							if ($btn_gridview == null) {
								var $gridview2 = $('.gridview2');

								$.ajax({
									url: toolbarUrl + row.id,
									type: 'get',
						            dataType: 'html',
									success:function(html){
										$html = $(html);
										$html.appendTo($gridview2);
										win.init($gridview2)

										$btn_gridview = $('#btn_gridview').gridView();

										$menuTable.gridView('resetView');
										$('#current_menu').val(row.id);
										$btn_gridview.data('data-menu',row.id);
									},
								})
								return;
							} else if ($btn_gridview.data('data-menu') == row.id) {
								return;
							}

							$btn_gridview.data('data-menu', row.id);
							console.log($btn_gridview.data('bootstrap.table'))
							$btn_gridview.data('bootstrap.table').options.url = toolbarUrl + row.id;
							$btn_gridview.bootstrapTable('refresh');
						})
			});

	

function format_status(status,row,index) {
	if(status == 1){
		return '显示'
	}else if(status == 2){
		return  '隐藏'
	}else if(status == 0){
		return  '禁止'
	}
}

function format_sort(sort,row,index) {
	return '<input type="text" class="form-control sort" data-id="'+row.id+'"  value="'+sort+'" />';
}
function fomat_icon(icon, row, index){
	return '<i class="fa '+icon+'"></i>';
}
function fomat_access(val, row, index){
	val +='';
	switch(val){
		case '-1':
			return '禁止访问';
		case '1':
			return '无限制';
		default:
			return '系统默认';
	}
}
function fomat_visible(val, row, index){
	return val == 1 ? '显示' : '不显示';
}
</script>
